﻿@using GoodMan.Infrastructure.Entities.Entity;
@{
    ViewBag.Title = "产品分类详情";
    Layout = "~/Areas/WorkSpace/Views/Shared/_CollegeAdminTemplete.cshtml";

    ItemListBox<ProductCategory> ParentCategorys = ViewBag.ParentCategorys;
    ProductCategory productCategory = ViewBag.Category;
    int id=productCategory==null?0:productCategory.Id;
}
@section head{
 <script type="text/javascript" src="/Scripts/jquery.js"></script>
    <script type="text/javascript" src="/Scripts/plug.js"></script>
    <link type="text/css" rel="Stylesheet" href="/content/css/select2.css" />
}
<div id="content-header">
    <h1>
        商品分类</h1>
</div>
<div id="breadcrumb">
    <a href="#" title="Go to Home" class="tip-bottom"><i class="icon-home"></i>首页</a>
    <a href="#" class="tip-bottom">商品管理</a> <a href="/workspace/CollegeAdmin/ProductCategory"
        class="current">商品分类</a> <a href="#" class="current">添加/编辑</a>
</div>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12">
            <div class="widget-box">
                <div class="widget-title">
                    <span class="icon"><i class="icon-align-justify"></i></span>
                    @{
                        if(id==0)
                        {
                            <h5>
                        添加商品分类</h5>
                        }
                        else
                        {
                        <h5>
                        编辑商品分类</h5>
                        }
                    }
                    
                </div>
                <div class="widget-content nopadding">
                    <form action="/CollegeAdmin/SaveProductCategory" id="productCategoryForm" method="post"
                    class="form-horizontal">
                    <div class="control-group">
                        <label class="control-label">
                            分类名称</label>
                        <div class="controls">
                            @{
                                if (productCategory != null)
                                {
                                <input type="hidden" name="productCategoryId" value="@productCategory.Id"/>
                                <input type="text" name="categoryName" value="@productCategory.CategoryName" placeholder="输入分类名称" style="width: 210px" class="span4 {required:true,messages:{required:'分类名称不能为空'}}"/><span style="color:Red;font-size:20px">&nbsp;&nbsp;*</span>
                                }
                                else
                                {
                                <input type="hidden" name="productCategoryId" value="0" />
                                <input type="text" name="categoryName" placeholder="输入分类名称" style="width: 210px"
                                     class="span4 {required:true,messages:{required:'分类名称不能为空'}}" /><span style="color:Red;font-size:20px">&nbsp;&nbsp;*</span>
                                }
                            }
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label">
                            上级分类</label>
                        <div class="controls">
                            <select name="parentID" id="parentID" style="width: 210px">
                                <option value="0">顶级分类</option>
                                @{
                                    if (ParentCategorys != null && ParentCategorys.Data != null && ParentCategorys.Data.Any())
                                    {
                                        foreach (var item in ParentCategorys.Data)
                                        {
                                            if (productCategory != null && productCategory.ParentId == item.Id)
                                            {
                                                <option value="@item.Id" selected="selected">@item.CategoryName</option>
                                            }
                                            else
                                            {
                                    <option value="@item.Id" >@item.CategoryName</option>
                                            }
                                        }
                                    }
                                }
                            </select>
                        </div>
                    </div>
                    @{
                                         
                        if (ViewBag.isSuccess != null)
                        {
                            if (ViewBag.isSuccess)
                            { 
                        <div class="alert alert-success">
                            <strong>商品分类保存成功！</strong>
                        </div>
                                                 
                            }
                            else
                            {
                        <div class="alert alert-error">
                            <strong>商品分类保存失败！</strong>
                        </div>
                                                 
                            }
                        }
                    }
                    <div class="form-actions">
                        <button type="submit" class="btn btn-primary">
                            保存</button>
                    </div>
                    </form>
                </div>
            </div>
        </div>
        @section tail{
        <script type="text/javascript" src="/scripts/select2.min.js"></script>
        <script type="text/javascript">
            $(function () {
                $('#likProduct').addClass('open');

                $('#likProduct').addClass('active');

                $('#parentID').each(function () {
                    $(this).select2();
                });
            });
            
    
        </script>
        <script type="text/javascript" src="/Scripts/jquery.validate.js"></script>
    <script type="text/javascript" src="/Scripts/jquery.metadata.js"></script>
    <script type="text/javascript" src="/Scripts/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript">
        var validation = new plug.BindValidCode();
        $(function () {
            validation.BindValidator();

            $('#productCategoryForm').validate({
                errorClass: "help-inline",
                errorElement: "span",
                highlight: function (element, errorClass, validClass) {
                    $(element).parents('.control-group').addClass('error');
                },
                unhighlight: function (element, errorClass, validClass) {
                    $(element).parents('.control-group').removeClass('error');
                }
            });
        });
        function Refalsh(sender) {
            validation.Refalsh(sender);
        }
    </script>
        }
    </div>
</div>
